package com.course.controller;

import com.course.entity.ResultBody;
import com.course.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/post")
@CrossOrigin(origins = "*")
public class PostController {
    @Autowired
    private PostService getpost;
    //发布帖子
    @RequestMapping("/getpost")
    public ResultBody getpost(@RequestBody Map<String,Object> map) {
        if (map.get("code") == null || map.get("name") == null || map.get("content") == null || map.get("usernumber") == null) {
            return new ResultBody(404, "参数错误", false);
        }
        return getpost.getpost(map);
    }
    //展示帖子
    @RequestMapping("/displaypost")
    public ResultBody displaypost()
    {
        return getpost.displaypost();
    }
    //添加评论（在帖子下的）
    @RequestMapping("/addcomment")
    public ResultBody addcomment(@RequestBody Map<String,Object> map)
    {
        if (map.get("code") == null || map.get("usernumber") == null || map.get("content") == null) {
            return new ResultBody(404, "参数错误", false);
        }
        return getpost.addcomment(map);
    }
    //展示评论（在帖子下的）
    @RequestMapping("/displaycomment")
    public ResultBody displaycomment(@RequestBody Map<String,Object> map)
    {
        if (map.get("code") == null) {
            return new ResultBody(404, "参数错误", false);
        }
        return getpost.displaycomment(map);
    }
    //删除帖子
    @RequestMapping("/deletepost")
    public ResultBody deletepost(@RequestBody Map<String,Object> map)
    {
        if (map.get("code") == null) {
            return new ResultBody(404, "参数错误", false);
        }
        return getpost.deletepost(map);
    }
}
